package com.tao.mytestgreendao;

import org.greenrobot.greendao.internal.SqlUtils;

/**
 * reate by tao on{DATE}
 */
public class MSqlUtils {


    public static String createSqlUpdate(String tablename, String[] updateColumns, String[] whereColumns) {
        String quotedTablename = '"' + tablename + '"';
        StringBuilder builder = new StringBuilder("UPDATE ");
        builder.append(quotedTablename).append(" SET ");
       appendColumnsEqualPlaceholders(builder, updateColumns);
        builder.append(" WHERE ");
        SqlUtils.appendColumnsEqValue(builder, quotedTablename, whereColumns);
        return builder.toString();
    }


    public static StringBuilder appendColumnsEqualPlaceholders(StringBuilder builder, String[] columns) {
        for (int i = 0; i < columns.length; i++) {
            SqlUtils.appendColumn(builder, columns[i]).append("=?");
            if (i < columns.length - 1) {
                builder.append(',');
            }
        }
        return builder;
    }

}
